export default {
  bind(el, binding) {
    el.style.pointerEvents = 'auto';
    let speed = typeof binding.value == 'number'? binding.value:1
    let scrollSpeed = speed
    let isScrolling = true
    el.addEventListener('mouseover', () => {
      isScrolling = false
    })
    el.addEventListener('mouseout', () => {
      isScrolling = true
    })
    const autoScrolling = function(){
      // if(el.scrollHeight && el.scrollHeight > 0 && el.scrollHeight === el.clientHeight){
      //   console.log('_______________________',el.scrollHeight,el.clientHeight)
      //   console.log(el.getBoundingClientRect())
      //   return;
      // }
      if (isScrolling) {
        if (el.scrollHeight - el.scrollTop <= el.clientHeight + 4) {
          el.scrollTop = 0;
        } else {
          el.scrollTop += scrollSpeed
        }
      }
      setTimeout(()=>{
        // requestAnimationFrame(autoScrolling)
        autoScrolling();
      },50)
    }
    autoScrolling(speed);
  }
}
